package com.woniuxy.education.mapper;

import com.woniuxy.education.entity.Perm;
import com.woniuxy.education.entity.Student;
import com.woniuxy.education.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where account = #{account}")
    public User findUserByAccont(String account);

    //查询具体的角色
    @Select("select * from student where u_id=#{id}")
    public Student findStudent(int id);

    //查出所有的rid
    @Select("select rid from user_role where uid = #{uid}")
    public List<Integer> findByRid(int uid);

    //查出所有的pid
    @Select("select pid from role_perms where rid = #{rid}")
    public List<Integer> findBypid(int rid);

    //通过pid查id
    @Select("select menuid from perms where pid = #{pid}")
    public List<Integer> findPermsid(int pid);

    //通过id查pid看看有没有子菜单
    @Select("select menuid from perms where pid = #{id}")
    public List<Integer> findAllPermsPid(int menuid);

    //通过id查权限
    @Select("select menuid,menuname,pid,icon,url from perms where menuid = #{id}")
    public Perm findPerm(int id);


    @Select("select * from user where account = #{account}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "roles",
                    many =@Many(select="com.woniuxy.shiro.mapper.RoleMapper.findRolesById"))
    })
    public User findUserAndRolesByAccont(String account);

    //修改学生的头像
    @Update("update student set head_picture = #{head_picture} where id= #{id}")
    public boolean changeStuPhone(@Param("id")int id,@Param("head_picture")String head_picture);

    //添加教师账号id,default,
    @Insert("insert into user (account,password,name) values (#{account},#{password},#{name})")
    boolean addUser(@Param("account") String account, @Param("password") String password,@Param("name") String name);
}
